package com.wsit.controller;


import com.wsit.pojo.Order;
import com.wsit.pojo.OrderPage;
import com.wsit.pojo.PageBean;
import com.wsit.pojo.Result;
import com.wsit.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("/commodity")
@RestController
@RequestMapping("/commodity")

public class Ordercontroller {
@Autowired
    private OrderService orderService;


/**
 * 分页查询订单表
 */
@ApiOperation(value = "查看订单表", notes = "查看订单表", httpMethod = "GET")
@GetMapping
public Result ServerPage(OrderPage orderPage) {
   PageBean pageBean = orderService.list(orderPage);
    return Result.success(pageBean);
}


/**
 * 添加订单
 */
@ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "Order", name = "order", value = "", required = true)
})
@ApiOperation(value = "添加订单", notes = "添加订单", httpMethod = "POST")
@PostMapping
    public Result add(@RequestBody Order order) {
    orderService.add(order);
    return Result.success();
}
/**
 * 根据id回显
 */
@ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
})
@ApiOperation(value = "根据id回显", notes = "根据id回显", httpMethod = "GET")
@GetMapping("/{id}")
public Result getById(@PathVariable Integer id) {
    Order order = orderService.getById(id);
    return Result.success(order);
}

/**
 * 修改订单
 */
@ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "Order", name = "order", value = "", required = true)
})
@ApiOperation(value = "修改订单", notes = "修改订单", httpMethod = "PUT")
@PutMapping
public Result update(@RequestBody Order order) {
    orderService.update(order);
    return Result.success();
}

}
